package rd.hardcore.engine.datas.streamBoard 
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IOErrorEvent;
	import flash.events.ProgressEvent;
	import flash.filesystem.File;
	import flash.filesystem.FileMode;
	import flash.filesystem.FileStream;
	import flash.net.URLLoader;
	import flash.net.URLLoaderDataFormat;
	import flash.net.URLRequest;
	import flash.utils.ByteArray;
	import fr.digitas.flowearth.command.Batch;
	import fr.digitas.flowearth.command.Batcher;
	import fr.digitas.flowearth.command.IBatchable;
	import fr.digitas.flowearth.net.BatchLoaderItem;
	import fr.digitas.flowearth.net.BatchURLLoaderItem;
	import nochump.util.zip.ZipEntry;
	import nochump.util.zip.ZipFile;
	import rd.hardcore.datas.Track;
	/**
	 * ...
	 * @author Fazermokeur
	 */
	public class BoardSynchroEngine extends EventDispatcher
	{
		private var _url:String;
		private var _name:String;
		private var fileCpt:int;
		private var _tab:Array;
		private var streamBoardDescriptor:XML;
		private var bPuce:BatchURLLoaderItem;
		private var bBackground:BatchURLLoaderItem;
		
		private var _vInstaller:Vector.<StreamBoardInstaller>;
		
		public function BoardSynchroEngine() 
		{
			_vInstaller = new Vector.<StreamBoardInstaller>();
		}
		
		public function setDatas(datas:XMLList):void
		{
			var node:XML;
			var f:File;
			var boardInstaler:StreamBoardInstaller;
			var id:int = 0;
			for each(node in datas.board) {
				var name:String = node.boardName;
				f =  new File(File.applicationStorageDirectory.resolvePath("boards/" + name + "/").nativePath);
				if (f.exists) {
					dispatchEvent(new StreamBoardSynchroEvent(StreamBoardSynchroEvent.STREAMBOARD_SYNCHONIZED, name));
				}else {
					boardInstaler = new StreamBoardInstaller(name, node.currentBoardURL);
					boardInstaler.addEventListener(Event.COMPLETE, handleComplete);
					boardInstaler.addEventListener(StreamBoardSynchroEvent.STREAMBOARD_SYNCHONIZED, dispatchEvent);
					_vInstaller.push(boardInstaler);
				}
				id++;
			}
			
		}
		
		private function handleComplete(e:Event):void 
		{
			(e.currentTarget as StreamBoardInstaller).removeEventListener(Event.COMPLETE, handleComplete);
		}
		
		
	}

}